﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace MoetutuServer.PublishHelper
{
    class Danran
    {
        public static string UploadFile(string FileName) {
            //
            string API = "https://zs.mtkan.cc/upload.php";
            Console.WriteLine("启动淡然上传");
            using (WebClient ImgUpLoad = new WebClient())
            {
                ImgUpLoad.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");

                try
                {
                    byte[] responseArray = ImgUpLoad.UploadFile(new Uri(API), FileName);
                    String JsonText = Encoding.UTF8.GetString(responseArray);
                    Console.WriteLine(JsonText);
                    Root AllJson = JsonConvert.DeserializeObject<Root>(JsonText);
                    if (AllJson.original_pic != null)
                       return AllJson.original_pic;

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            return "";
        }


        public class Root
        {
            /// <summary>
            /// 
            /// </summary>
            public string original_pic { get; set; }
        }
    }
}
